package web.servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by user on 01.06.2014.
 */
@WebFilter("/test")
public class UserFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest serReq = (HttpServletRequest) request;
        String ua = serReq.getHeader("User-Agent");
        if (ua.contains("MSIE")) {
            request.setAttribute("ie", true);
        } else {
            request.setAttribute("ie", false);
        }
        ((HttpServletResponse) response).encodeRedirectURL("./error.jsp");
        filterChain.doFilter(request, response);

    }

    public void destroy() {

    }
}
